package com.itgaoshu.hospitalproject.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itgaoshu.hospitalproject.bean.Registeredtype;
import com.itgaoshu.hospitalproject.service.RegisteredtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("registeredType")
public class RegisteredtypeController {
    @Autowired
    private RegisteredtypeService registeredtypeService;

    //查询所有挂号类型的方法
    @ResponseBody
    @RequestMapping("registeredTypeList")
    public Object registeredTypeList(String type,Integer page,Integer limit){
        PageHelper.startPage(page,limit);
        List<Registeredtype> registeredtypes = registeredtypeService.registeredTypeList(type);
        PageInfo pageInfo = new PageInfo(registeredtypes);
        Map<String,Object> tableData = new HashMap<>();
        tableData.put("msg","");
        tableData.put("code",0);
        tableData.put("count",pageInfo.getTotal());
        tableData.put("data",pageInfo.getList());
        return tableData;
    }


    //添加挂号类型的方法
    @RequestMapping("addRegisteredType")
    @ResponseBody
    public  Object addRegisteredType(Registeredtype registeredtype){
        int count = registeredtypeService.count(registeredtype);
        if (count==0){
            int result = registeredtypeService.addRegisteredType(registeredtype);
            if(result>0){
                return "添加成功";
            }else{
                return "添加失败";
            }
        }else{
            return "这个挂号类型已经存在了哦";
        }
    }


    //修改挂号类型的方法
    @ResponseBody
    @RequestMapping("editRegisteredType")
    public Object editRegisteredType(Registeredtype registeredtype){
        int result = registeredtypeService.editRegisteredType(registeredtype);
        if(result>0){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }


}
